import { fileURLToPath, URL } from 'node:url'

import { defineConfig, ConfigEnv, UserConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// 配置自动导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig((confDev: ConfigEnv): UserConfig => {
  console.log(confDev)
  return {
    server: {
      host: '0.0.0.0',
      port: 3000
    },
    plugins: [
      vue(),
      vueJsx(),
      AutoImport({
        //

        imports: ['vue', 'vue-router' ],
        resolvers: [ElementPlusResolver()],
        vueTemplate: true,
        dts: 'src/types/auto-imports.d.ts',
        eslintrc: {
          enabled: false, // Default `false`
          filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json
          globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable'
        }
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      createSvgIconsPlugin({
        iconDirs: [resolve(__dirname,'./src/assets/icons')],
        symbolId: '[name]'
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
        _pinia: fileURLToPath(new URL('./src/stores/modules', import.meta.url))
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/styles/modules/variable.scss" as *;`
        }
      }
    }
  }
})
